const { name } = require("file-loader");
const { options, watch } = require("less");
const { type } = require("os");
const path = require("path");
const { plugin } = require("postcss");
const { DefinePlugin, Template } = require("webpack");

// const { DefinePlugin } = require("webpack");
const { title } = require("process");
const { VueLoaderPlugin } = require ("vue-loader/dist/index");
const { gzip } = require("zlib");
// const  CopyWebpackPlugin  = require("copy-webpack-plugin");
module.exports = {

    target:"web",

    entry:"./src/main.js",
    output:{
        path:path.resolve(__dirname,"../build"),
        filename:"bundle.js"
    },
   
    resolve:{
     extensions:[".js",".vue",".json",".ts",".mjs",".jsx",".tsx"]
    },
    module:{
        rules:[
            {
                test:/\.css$/,
                use:[
                    "style-loader",
                    "css-loader",
                    "postcss-loader"
                    
                ]
            },
            {
                test:/\.less$/,
                use:[
                    "style-loader",
                    "css-loader",
                    "less-loader"
                ]
            },
            {
                test:/\.(jpg|jpe?g|png|svg|gif)$/,
                type: "asset",
                generator:{
                 filename:"img/[name]_[hash:6][ext]"
                },
                parser:{
                    dataUrlCondition:{
                        maxSize:100*1024
                    }
                }
            },
            {
                test:/\.(eot|ttf|woff2?)$/,
                use:{
                    loader:"file_loader",
                    options:{
                     name:"font/[name]_[hash:6].[ext]"
                    }
                }
            },
            {
                test:/\.js$/,
                use:"babel-loader"
            },
            {
                test:/\.vue$/,
                use:"vue-loader"
            }
        ]

    },
    plugins:[
        new HtmlWebpackPlugin({
            template :"./public/index.html",
            title:"标题"
        }),
        new DefinePlugin({
            BASE_URL:"'./'",
            __VUE_OPTIONS_API__:true,
            __VUE_PROD_DEVTOOLS__:false
        }),
        new VueLoaderPlugin()
    ]
}
